<template>
	<view>
		<view class="page-body">
			<view class="page-section page-section-gap" v-if="isSend">
				<map style="width: 100%; height: 300px;" :latitude="latitude" :longitude="longitude" scale="16"> </map>
			</view>
			<view @click="goback()">
				<u-button type="primary" text="确定" ></u-button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				markers: [{}, {}, {}],
				poisdatas: [{}, {}, {}],
				title: 'map',
				datas :{},
				longitude: 0,
				isSend:false,
			
			}
		},
		onLoad() {

			var amapFile = require('../../../config/amap-wx.130.js');
			var amapPlugin = new amapFile.AMapWX({
				key: "b7f8fd41556d76bc5ad78438767f89b6"
			});
			amapPlugin.getRegeo({
				success: (data) => {
					console.log(data[0].latitude);
					console.log( data[0].longitude);
					this.datas.latitude = data[0].latitude
					this.datas.longitude = data[0].longitude
					this.isSend = true
				}
			})

			amapPlugin.getPoiAround({
				success: (data) => {
					// console.log(data);
					//成功回调
					this.markers = data.markers;
					this.poisdatas = data.poisData;
					var markers_new = [];
					this.markers.forEach((item, index) => {

						// aa
						markers_new.push({
							id: item.id, //marker 序号
							width: item.width, //marker 宽度
							height: item.height, //marker 高度
							iconPath: item.iconPath, //marker 图标路径
							latitude: item.latitude, //marker  纬度
							longitude: item.longitude, //marker 经度
							//自定义标记点上方的气泡窗口
							callout: {
								padding: 2, //callout 文本边缘留白
								fontSize: 15, //callout  文字大小
								bgColor: 'blue', //callout 背景颜色
								color: '#6B8E23', //callout 文字颜色
								borderRadius: 5, //边框圆角
								display: 'BYCLICK', //callout 'BYCLICK':点击显示; 'ALWAYS':常显
								content: this.poisdatas[index].name //地理位置名称
							}
						})
					})
					this.markers = markers_new;
				},
				fail: (info) => {
					//失败回调
					console.log("info", info)
				}
			})
		},
		methods: {
			//得到点击的marker的id，遍历markers数组，判断有没有相等的id
			//如果有的就能从this.poisdatas[i].address得到坐标位置（没有就提醒下）
			markertap: function(e) {
				for (var i = 0; i < this.markers.length; i++) {
					if (JSON.stringify(e).substring(18, 20) == this.markers[i].id) {
						console.log("markers" + this.poisdatas[i].name + "   " + this.poisdatas[i].address);
						uni.showToast({
							title: this.poisdatas[i].name,
							mask: false,
							duration: 1500
						});
					}
				}

			},
			goback()
			{
					// console.log(this.datas);
			let pages = getCurrentPages()
			let currPage = pages[pages.length - 1] //当前页面
			let prevPage = pages[pages.length - 2] //上一个页面
			//直接调用上一个页面的setData()方法，把数据存到上一个页面中去
			prevPage.$vm.datas =JSON.stringify(this.datas),
			uni.navigateBack()
				
				// uni.navigateTo({
				// 	url: '../../fun/confirm_seat/confirm_seat?GPS='+ JSON.stringify(this.datas)
				// })
				
				if(this.datas == null)
				{
					
				}
			}
		}
	}
</script>

<style>
</style>
